# -*- coding: utf-8 -*-

###########################################################
#                                                         #
# shooter - shooter game                                  #
#                                                         #
# 2011 - Andreas Grätz                                    #
#                                                         #
# andreaszdw@googlemail.com                               #
#                                                         #
# menustate.py                                            #
#                                                         #
###########################################################

from PySFML import sf
import state
import playstate
import random
import math

class MenuState(state.State):
	
	def __init__(self):
		print "menustate - __init__"
	
	def __del__(self):
		pass
		
	def init(self, window):
		self.running = True
		self.countResume = 0
		
		self.Font = sf.Font()
		self.Font.LoadFromFile("../font/Ubuntu-L.ttf")
		self.Text = sf.String()
		self.Text.SetText("FPS:")
		self.Text.SetFont(self.Font)
		self.Text.SetPosition(10, 10)
		
		self.nextState = False
		self.popState = False
		
		self.image_bg = sf.Image()
		self.image_bg.LoadFromFile("../gfx/bg_menu.png")
		self.sprite_bg = sf.Sprite(self.image_bg)
		self.sprite_bg.SetPosition(0, 0)
		
		self.clock = sf.Clock()
		self.clock2 = sf.Clock()

		self.frame = 0
		self.frame2 = 0
		self.clock.Reset()
		self.clock2.Reset()
	
	def cleanup(self):
		print "menustate: I clean up"
		
	def handleevents(self, window):	
		event = sf.Event()
		
		while window.GetEvent(event):
			if event.Type == sf.Event.Closed:
				self.running = False

			if event.Type == sf.Event.KeyPressed:
				if event.Key.Code == sf.Key.Escape:
					self.running = False
				else:
					self.nextState = playstate.PlayState
	
	def update(self, window):
		pass
	
	def pause(self):
		print "menustate - pause"
	
	def resume(self):
		self.countResume += 1
		print "menustate - resume %d" % self.countResume
	
	def draw(self, window):
		window.Clear()
		window.Draw(self.sprite_bg)
		window.Draw(self.Text)
		window.Display()
		self.frame += 1
		self.frame2 += 1
		if self.clock.GetElapsedTime() > 1:
			self.Text.SetText("Fps: %i" % self.frame)
			self.frame = 0
			self.clock.Reset()

	def isrunning(self):
		return self.running
